package com.zzxx.photograph.dao.impl;

import com.zzxx.photograph.dao.AuthorDao;
import com.zzxx.photograph.domain.Author;
import com.zzxx.photograph.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class AuthorDaoImpl implements AuthorDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public Author findByAid(Integer aid) {
        String sql = "select * from author where aid=?";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Author.class), aid).get(0);
    }

    @Override
    public void addAuthor(Author author) {
        String sql="insert into author values(?,?,?)";
        jdbcTemplate.update(sql,author.getAid(),author.getAname(),author.getTelephone());
    }
}

